using System;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for RCAccountClass
/// </summary>
public partial class SqlServerProvider
{
    public bool SavePostJob()
    {
        bool save = false;
        errorMessage = "";
        try
            {
            sqlCommand = new SqlCommand();
            sqlCommand.CommandText = "SPSavePostJob";
            sqlCommand.Connection = sqlConnection;
            sqlCommand.CommandType =
            CommandType.StoredProcedure;
            AddParameters(sqlCommand);
            save = (sqlCommand.ExecuteNonQuery()>0);        
            CloseConnection();
        }
        catch (SqlException sql)
        {
            errorCode = sql.Number;
            errorMessage = sql.Message;
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return save;
    }
   public string NewRCAccount(
   string email,  
   string passWord,
   string companyName,
   string englishName, 
   string accountType,
    string newsletter,
   string promotion, string resumeAlert
   )
    {
        errorMessage = "";
        string userID = "";
        try
        {

            sqlCommand = new SqlCommand();
            sqlCommand.CommandText = "SPRCAccount";
            sqlCommand.Connection = sqlConnection;
            sqlCommand.CommandType =
            CommandType.StoredProcedure;

            sqlCommand.Parameters.AddWithValue(
            "@UserID", "0");
            sqlCommand.Parameters.AddWithValue(
            "@Email", email);
            sqlCommand.Parameters.AddWithValue(
            "@Password", passWord);
            sqlCommand.Parameters.AddWithValue(
            "@CompanyName", companyName);
            sqlCommand.Parameters.AddWithValue(
            "@EnglishName", englishName);
            sqlCommand.Parameters.AddWithValue(
            "@AccountType", accountType);
            sqlCommand.Parameters.AddWithValue(
            "@Newsletter", newsletter);
            sqlCommand.Parameters.AddWithValue(
            "@ResumeAlert", resumeAlert);
            sqlCommand.Parameters.AddWithValue(
            "@Promotion", promotion);

            SqlParameter sqlParameter =
            new SqlParameter("@ReturnValue", "");
            sqlParameter.Direction = ParameterDirection.ReturnValue;
            sqlCommand.Parameters.Add(sqlParameter);

            sqlCommand.ExecuteNonQuery();
            userID = Convert.ToString(sqlParameter.Value);

            CloseConnection();
        }
        catch (SqlException sql)
        {
            errorCode = sql.Number;
            errorMessage = sql.Message;
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return userID;
    }

    public bool UpdateRCAccount(string userID,
        string email,
       string companyName,
       string englishName,
       string accountType,
        string newsletter,
       string promotion, 
       string resumeAlert)
    {
        errorMessage = "";
        bool update = false;
        try
        {

            sqlCommand = new SqlCommand();
            sqlCommand.CommandText = "SPRCAccount";
            sqlCommand.Connection = sqlConnection;
            sqlCommand.CommandType =
            CommandType.StoredProcedure;

            sqlCommand.Parameters.AddWithValue(
            "@UserID", userID);
            sqlCommand.Parameters.AddWithValue(
            "@Email", email);
            sqlCommand.Parameters.AddWithValue(
                        "@Password", "");
            sqlCommand.Parameters.AddWithValue(
            "@CompanyName", companyName);
            sqlCommand.Parameters.AddWithValue(
            "@EnglishName", englishName);
            sqlCommand.Parameters.AddWithValue(
            "@AccountType", accountType);
            sqlCommand.Parameters.AddWithValue(
            "@Newsletter", newsletter);
            sqlCommand.Parameters.AddWithValue(
            "@ResumeAlert", resumeAlert);
            sqlCommand.Parameters.AddWithValue(
            "@Promotion", promotion);

            sqlCommand.ExecuteNonQuery();
            update = true;
            CloseConnection();
        }
        catch (SqlException sql)
        {
            errorCode = sql.Number;
            errorMessage = sql.Message;
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return update;
    }

    public bool UpdateCompany(
    string userID,
    string contact,
    string address,
     string city,
    string tel,
    string fax,
   
    string country,
    string province,
    string opendate
    )
    {
        errorMessage = "";
        bool update = false;
        try
        {

            sqlCommand = new SqlCommand();
            sqlCommand.CommandText = "SPRCCompany";
            sqlCommand.Connection = sqlConnection;
            sqlCommand.CommandType =
            CommandType.StoredProcedure;
            sqlCommand.Parameters.AddWithValue(
            "@RecruiterID", userID);
            sqlCommand.Parameters.AddWithValue(
            "@Contact", contact);
            sqlCommand.Parameters.AddWithValue(
            "@Address", address);
            sqlCommand.Parameters.AddWithValue(
            "@ProvinceID", province);
            sqlCommand.Parameters.AddWithValue(
            "@City", city);
            sqlCommand.Parameters.AddWithValue(
            "@OpenDate", opendate);
            sqlCommand.Parameters.AddWithValue(
            "@Tel", tel);
            sqlCommand.Parameters.AddWithValue(
            "@Fax", fax);
            sqlCommand.Parameters.AddWithValue(
            "@Country", country);

            sqlCommand.ExecuteNonQuery();
            update = true;
            CloseConnection();
        }
        catch (SqlException sql)
        {
            errorCode = sql.Number;
            errorMessage = sql.Message;
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return update;
    }

    public bool DeleteAppliedResume(string recruiterID, string jobID, string resumeID)
    {
        bool deleteItem = false;
        errorMessage = "";
        try
        {
            OpenConnection();
            sqlCommand = new SqlCommand();
            sqlCommand.CommandText = "SPDeleteAppliedResume";
            sqlCommand.Connection = sqlConnection;
            sqlCommand.CommandType =
            CommandType.StoredProcedure;
            sqlCommand.Parameters.AddWithValue(
            "@RecruiterID", recruiterID);
            sqlCommand.Parameters.AddWithValue(
            "@ResumeID", resumeID);
            sqlCommand.Parameters.AddWithValue(
            "@JobID", jobID);
            deleteItem = (sqlCommand.ExecuteNonQuery() > 0);
            CloseConnection();
        }
        catch (SqlException sql)
        {
            errorCode = sql.Number;
            errorMessage = sql.Message;
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return deleteItem;
    }
    public bool ChangeStatusOfResume(string recruiterID, string jobID, string resumeID, string status)
    {
        bool deleteItem = false;
        errorMessage = "";
        try
        {
            OpenConnection();
            sqlCommand = new SqlCommand();
            sqlCommand.CommandText = "SPChangeAppliedResume";
            sqlCommand.Connection = sqlConnection;
            sqlCommand.CommandType =
            CommandType.StoredProcedure;
            sqlCommand.Parameters.AddWithValue(
            "@RecruiterID", recruiterID);
            sqlCommand.Parameters.AddWithValue(
            "@ResumeID", resumeID);
            sqlCommand.Parameters.AddWithValue(
            "@JobID", jobID);
            sqlCommand.Parameters.AddWithValue(
            "@Status", status);
            deleteItem = (sqlCommand.ExecuteNonQuery() > 0);
            CloseConnection();
        }
        catch (SqlException sql)
        {
            errorCode = sql.Number;
            errorMessage = sql.Message;
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return deleteItem;
    }
}
